"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.拳师Handler = void 0;
const Config_1 = require("../../Config");
const Big_1 = require("../core/Big");
const GameUtils_1 = __importDefault(require("../GameUtils"));
const BaseHandler_1 = require("./BaseHandler");
class 拳师Handler extends BaseHandler_1.BaseHandler {
    /**
     * 攻击时行动力消耗-1，相当于移动
     */
    拳师_移动(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_拳师_移动);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        let big_end = endPoint.big;
        if (big_end != null) {
            big_end.deleteState(Big_1.BigState.HIDE);
            big_start.die(player, endPoint.id);
            return;
        }
        //没有大子，就是移动
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("big_move", { "start": data.start, "end": data.end }));
        big_start.terrainAdapt();
    }
    /**
     * 攻击成功后周围一圈大子和父系大子获得怯战
     */
    拳师_怒威神拳(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_拳师_怒威神拳);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        let small = endPoint.small;
        let big_end = endPoint.big;
        if (small != null) {
            //小子被攻击
            small.die(player);
        }
        else if (big_end != null) {
            let big_end_father = big_end.father;
            //大子被攻击
            if (big_end.attacked(player)) {
                let qs = big_start;
                //打过了
                if (big_end_father != null) {
                    big_end_father.addState(Big_1.BigState.FEAR);
                    qs.addMark(big_end_father);
                }
                else {
                    qs.removeMark();
                }
            }
            else {
                //攻击没打过，自己死亡
                big_start.die(player, endPoint.id);
                return;
            }
        }
        //没有大子，就是移动
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("拳师_怒威神拳", { "start": data.start, "end": data.end }));
        big_start.terrainAdapt();
    }
    /**
     * AOE伤害
     */
    拳师_爆裂火拳(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_拳师_爆裂火拳);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        let small = endPoint.small;
        let big_end = endPoint.big;
        if (small != null) {
            //小子被攻击
            small.die(player);
        }
        else if (big_end != null) {
            //大子被攻击
            if (big_end.attacked(player)) {
                //打过了
            }
            else {
                //攻击没打过，自己死亡
                big_start.die(player, endPoint.id);
                return;
            }
        }
        let list = GameUtils_1.default.getArrPointsAround(this.gameMgr, endPoint);
        for (let p of list) {
            let b = p.big;
            if (b != null && b.player != player) {
                b.attacked(player);
            }
        }
        //没有大子，就是移动
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("拳师_爆裂火拳", { "start": data.start, "end": data.end }));
        big_start.terrainAdapt();
    }
}
exports.拳师Handler = 拳师Handler;
